package com.cz.video.website.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.cz.video.common.annotation.LegalValidate;
import com.cz.video.common.annotation.Log;
import com.cz.video.common.core.controller.BaseController;
import com.cz.video.common.core.domain.PageQuery;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.core.page.TableDataInfo;
import com.cz.video.common.core.validate.EditGroup;
import com.cz.video.common.enums.BusinessType;
import com.cz.video.common.utils.ValidatorUtils;
import com.cz.video.website.domain.WebsiteMediaCategory;
import com.cz.video.website.domain.bo.WebsiteMediaCategoryBo;
import com.cz.video.website.domain.vo.WebsiteMediaCategoryVo;
import com.cz.video.website.service.IWebsiteMediaCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 电影分类表 前端控制器
 * </p>
 *
 * @author 洪圆胜
 * @since 2023-10-15
 */
@Tag(name = "电影分类管理")
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("/website/media/category")
public class WebsiteMediaCategoryController extends BaseController {

    private final IWebsiteMediaCategoryService websiteMediaCategoryService;

    @SaCheckPermission("website:mediaCategory:add")
    @Log(title = "添加分类", businessType = BusinessType.INSERT)
    @Operation(summary = "添加分类")
    @PostMapping("")
    @LegalValidate
    public R<Void> add(@RequestBody @Validated WebsiteMediaCategoryBo websiteMediaCategory){
        return toAjax(websiteMediaCategoryService.addMediaCategory(websiteMediaCategory));
    }

    @SaCheckPermission("website:mediaCategory:delete")
    @Operation(summary = "删除电影分类")
    @Log(title = "删除电影分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id){
        return toAjax(websiteMediaCategoryService.removeById(id));
    }

//    @SaCheckPermission("website:mediaCategory:edit")
    @Log(title = "修改电影分类", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改电影分类")
//    @LegalValidate
    @PutMapping("")
    public R<Void> edit(@RequestBody  WebsiteMediaCategoryBo websiteMediaCategory){
        ValidatorUtils.validate(websiteMediaCategory, EditGroup.class);
        return toAjax(websiteMediaCategoryService.update(websiteMediaCategory));
    }

    @SaCheckPermission("website:mediaCategory:view")
    @Log(title = "查看电影分类", businessType = BusinessType.SELECT)
    @Operation(summary = "查看电影分类")
    @GetMapping("/{id}")
    public R<WebsiteMediaCategory> view(@PathVariable Long id){
        WebsiteMediaCategory websiteMediaCategory = websiteMediaCategoryService.getById(id);
        return R.ok(websiteMediaCategory);
    }

    @SaIgnore
    @Operation(summary = "分页查询分类列表")
    @GetMapping("/list")
    public TableDataInfo<WebsiteMediaCategoryVo> page(WebsiteMediaCategoryBo websiteMediaCategory, PageQuery pageQuery){
        return websiteMediaCategoryService.page(websiteMediaCategory, pageQuery);
    }

}
